Contents | Index | < Browse | Browse >

LETTERqsortULETTER Quick-sorts an array.

Overview
#include <stdlib.h>

(void) qsort(array, members, size, compare);

void *array;
size_t members;
size_t size;
int (*compare)(const void *, const void *);

Portability
ANSI

Description
This function performs a quick-sort (also known as the ACM 271 algorhytm) on the array "array" which has "members" members with a size of "size" bytes. If required, members will be exchanged through byte-wise copying.

You need to specify a comparison function "compare". It'll get pointers to two of the array's members passed and must return a value greater than 0 if the first element is bigger than the second, zero if both elements are equal and a value smaller than 0 if the first element is smaller than the second.

The sort process will of course perform faster if the array contains pointers to bigger objects (such as strings) instead of the objects themselves.

See also
strcmp